﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Edit</title>
    <link href="~/Content/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/lib/layui/layui.js"></script>
</head>
<body>
    <form class="layui-form" action="">
        <input type="hidden" value="@ViewBag.A.id" id="id" />
        <div class="layui-form-item">
            <label class="layui-form-label">轮播图标题</label>
            <div class="layui-input-block">
                <input type="text" value="@ViewBag.A.title" id="title" required lay-verify="required" placeholder="请输入轮播图标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人</label>
            <div class="layui-input-block">
                <input type="text" value="@ViewBag.A.create_user" id="create_user" required lay-verify="required" placeholder="请输入创建人" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图片</label>
            <div class="layui-input-block">
                <input type="file" id="my_file" name="file">
                <input type="text" id="bannerImg" value="@ViewBag.A.bannerImg" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <img id="my_img" src="/images/@ViewBag.A.bannerImg" style="width:200px;height:200px" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">跳转地址</label>
            <div class="layui-input-block">
                <input type="text" value="@ViewBag.A.url" id="url" required lay-verify="required" placeholder="请输入跳转地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        //Demo
        layui.use(['form', 'upload'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var $ = layui.$;
            upload.render({
                elem: "#my_file",
                url: "/Back/Home/UploadImg",
                done: function (res) {
                    if (res.code == 0) {
                        $("#my_img").attr("src", "/images/" + res.path);
                        $("#bannerImg").val(res.path);
                    }
                }
            })
            //监听提交
            form.on('submit(formDemo)', function (data) {
                $.ajax({
                    url: "/Back/Banner/DealEdit",
                    type: "post",
                    data: {
                        id: $("#id").val(),
                        title: $("#title").val(),
                        url: $("#url").val(),
                        bannerImg: $("#bannerImg").val(),
                        create_time: $("#create_time").val(),
                        create_user: $("#create_user").val(),
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            parent.layer.close()
                            parent.location.reload()
                        }
                    }
                })
                return false;
            });
        });
    </script>
</body>
</html>
